/*
 * @Author: hongbin
 * @Date: 2022-11-19 10:37:31
 * @LastEditors: hongbin
 * @LastEditTime: 2022-12-08 11:50:57
 * @Description:
 */

import { useState, useCallback } from "react";

const baseInfo = {
    name: "",
    password: "",
    conformPassword: "",
    // 学院
    college: "",
    // 专业
    major: "",
    // 兴趣
    interest: "",
    // 交友格言 (声明)
    statement: "",
    sex: "男" as "女" | "男",
    age: 20,
};

/**
 * 朋友信息
 * 添加朋友的日期
 * 朋友的id
 * 和朋友的聊天记录
 */
export interface IFriends {
    date: number;
    friendId: string;
    chatRecordId: string;
}

interface IDataUserInfo {
    _id: string;
    friendsList: Array<IFriends>;
    mail: string;
    chat: string;
    qq: string;
    /**
     * 公开联系资料
     */
    public: boolean;
}

export type UserInfo = Omit<typeof baseInfo & IDataUserInfo, "conformPassword" | "password">;

export const useRegisterForm = () => {
    const [info, setInfo] = useState(baseInfo);

    const setValue = useCallback(
        (key: keyof typeof info) => (val: string | number) => {
            setInfo((prev) => ({ ...prev, [key]: val }));
        },
        []
    );

    return [info, setValue] as [typeof info, typeof setValue];
};
